package org.example.modules.user.controller;

import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.example.common.utils.ThreadLocalUtil;
import org.example.modules.user.common.Commsult;
import org.example.modules.user.entry.User;
import org.example.modules.user.entry.UserAddress;
import org.example.modules.user.mapper.UserAddressMapper;
import org.example.modules.user.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description UserAddressController
 * @Author xiaotian
 * @Date 2025-04-17
 */
@RestController
@RequestMapping("/wxApi/Address")
@Slf4j
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    @PostMapping
    public Commsult<List<UserAddress>> addAddress(@RequestBody JSONObject data){
        userAddressService.saveAddress(data);
        return Commsult.success(userAddressService.getAllAddress());
    }

    @GetMapping("/getUserAddress/{userName}")
    public Commsult<List<UserAddress>> getUserAddress(@PathVariable String userName){
        return Commsult.success(userAddressService.getAllAddress());
    }
    @PostMapping("/updateDefault")
    public Commsult updateDefaultAddress(@RequestBody JSONObject data){
        userAddressService.updateDefaultAddress(data);
        return Commsult.success(null);
    }
    @GetMapping("/getDefault")
    public Commsult<UserAddress> getDefaultAddress(){
        return Commsult.success(userAddressService.getDefaultAddress());
    }

}
